<?php

/**
 * @author Samrat Khan & Sadik Sarfaraz - 5:19:44 PM Sep 26, 2013 
 */

require('top.inc.php');
$formLoad = new Form();
if(isset($_SESSION['user']) && $_SESSION['user']['utype'] == 1 || $_SESSION['user']['utype'] == 2 || $_SESSION['user']['utype'] == 3 || $_SESSION['user']['utype'] == 4) {
    $sess_userID = $_SESSION['user']['id'];
    if($_GET['stc_id']) {
        $stc_id = $_GET['stc_id'];
        
        echo '<form name="ModifyStc" id="modifyStc" method="post" action="modify.php">';
            echo "<table class=\"form-inline row-fluid table table-striped table-bordered\">";
                echo "<tr>";
                    echo "<th>" . $stc['serialno'] . "</th>";
                    echo "<th>" . $stc['faulties_id'] . "</th>";
                    echo "<th>" . $stc['wh_stc_no'] . "</th>";
                    echo "<th>" . $stc['cus_stc_no'] . "</th>";
                    echo "<th>" . $stc['report'] . "</th>";
                    echo "<th>" . "&nbsp;" . "</th>";
                echo "</tr>";

            $row = selectSingleStc($stc_id, $db);
            foreach ($row as $single) {
                echo "<tr>";
                    echo '<input type="hidden" name="stc_id" value="'.$single['stc_id'].'" />';
                    echo "<td>" . $formLoad->textFieldReadyOnly('serialno', 'serialno', 'serialno', $readonly, '', $single['serialno']) . "</td>";
                    echo "<td>" . $formLoad->textFieldReadyOnly('faulties_id', 'faulties_id', 'faulties_id', $readonly, '', $single['faulties_id']) . "</td>";
                    echo "<td>" . $formLoad->textFieldReadyOnly('wh_stc_no', 'wh_stc_no', 'wh_stc_no', $readonly, '', $single['wh_stc_no']) . "</td>";
                    echo "<td>" . $formLoad->textField('cus_stc_no', "cus_stc_no", "cus_stc_no", '', $single['cus_stc_no']) . "</td>";
                    echo "<td>";
                        echo "<select name='report'>";
                            echo "<option value='' selected>". "Select..." ."</option>";
                            echo "<option value='1'>". "PASS" ."</option>";
                            echo "<option value='0'>". "FAIL" ."</option>";

                        echo "</select>";
                    echo "</td>";

                    echo '<input type="hidden" name="userid" value="'.$_SESSION['user']['id'].'" />';
                    echo '<input type="hidden" name="cus_id" value="'.$_SESSION['user']['cus_id'].'" />';
                    echo '<input type="hidden" name="session_id" value="'.  session_id() .'" />';
                    echo '<input type="hidden" name="junkentry" value="0" />';
                    echo "<td>";
                        echo '<input id="ModifyStcenterBtn" class="btn btn-primary" type="submit" value="Save Info" name="ModifyStc" />';
                    echo "</td>";
                echo "</tr>";
            }
        echo "<table>";
        echo '</form>';
    } else {
        
        $sess_userID = $_SESSION['user']['id'];
        $rows1 = modifyStc($sess_userID, $db);
        
        echo "<table class=\"row-fluid table table-striped table-bordered\">";
            echo "<tr>";
                echo "<th>" . $optionsIcons['optionIcon'] . "</th>";
                echo "<th>" . $stc['serialno'] . "</th>";
                echo "<th>" . $faulties['productid'] . "</th>";
                echo "<th>" . $faulties['description'] . "</th>";
                echo "<th>" . $faulties['revisionstate'] . "</th>";
                echo "<th>" . $faulties['rma'] . "</th>";
                echo "<th>" . $stc['wh_stc_no'] . "</th>";
                echo "<th>" . $stc['cus_stc_no'] . "</th>";
                echo "<th>" . $stc['report'] . "</th>";
                echo "<th>" . $faulty_export['userid'] . "</th>";
                echo "<th>" . $customer_info['cusname'] . "</th>";
                echo "<th>" . $faulty_export['inserteddate'] . "</th>";
            echo "</tr>";
            foreach ($rows1 as $row) {
                echo "<tr>";
                echo "<td>";
                echo "<a class='btn btn-success btn-mini' href='modify-stc.php?stc_id={$row['stc_id']}'>" . $optionsIcons['update'] . "</a>";
                echo "</td>";
                echo "<td>" . $row['serialno'] . "</td>";
                echo "<td>" . $row['productid'] . "</td>";
                echo "<td>" . $row['description'] . "</td>";
                echo "<td>" . $row['revisionstate'] . "</td>";
                echo "<td>" . $row['rma'] . "</td>";
                echo "<td>" . $row['wh_stc_no'] . "</td>";
                echo "<td>" . $row['cus_stc_no'] . "</td>";
                echo "<td>";
                    if($row['report'] == 1) {
                        echo "PASS";
                    } else {
                        echo "FAIL";
                    }
                echo "</td>";            
                echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
                echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
                echo '<input type="hidden" name="session_id" value="' . session_id() . '" />';
                echo '<input type="hidden" name="junkentry" value="0" />';
                echo "<td>" . $row['inserteddate'] . "</td>";
                echo "</tr>";
            }
            echo "<table>";
    }
}
?>
